<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>影院票务管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/front/style/CSS/normalize.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/front/style/CSS/dianying.css">
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/front/style/IMG/Blogo.png" type="image/x-icon">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/front/layui/css/layui.css">

</head>

<body>
<!-- 顶部 -->
<header class="dingbu">
    <nav>
        <a href="#" class="logo"></a>
        <ul class="navbar">
            <li>
                <a href="${pageContext.request.contextPath}/front/index.jsp">首页</a>
            </li>
            <li>
                <a href="${pageContext.request.contextPath}/front/movie.jsp">电影</a>
            </li>
            <li>
                <a href="${pageContext.request.contextPath}/front/filmRank.jsp">排行榜</a>
            </li>
            <li>
                <a href="${pageContext.request.contextPath}/front/screening.jsp">场次安排</a>
            </li>
            <li>
                <a href="${pageContext.request.contextPath}/front/vipRecharge.jsp">会员卡</a>
            </li>
            <li>
                <a href="${pageContext.request.contextPath}/front/userOrders.jsp">个人信息</a>
            </li>
        </ul>

        <div class="sousuo">
        </div>
        <div class="denglu bian">
            <a href="#">
                <img src="${pageContext.request.contextPath}/front/style/IMG/avatar.png" alt="">
            </a>
            <span class="sanjiao"></span>
            <div>
                <a id="showStatus" href="${pageContext.request.contextPath}/front/accountLogin.jsp">登录</a>
            </div>
        </div>
    </nav>
</header>
<!-- 大类 -->
<div class="header">
    <ul>
        <li>
            <a href="#">正在热映</a>
        </li>
    </ul>
</div>
<!-- 主体 -->
<div class="main">
    <article>
        <!-- 电影详细分类 -->
        <div class="lei">
            <ul class="lei_1">
                <li>
                    <div style="height: 0px">
                        类型：
                    </div>
                    <ul class="lei_2" >
                        <li id="type">
                            <input type="radio" id="quanbu" name="leixing" checked>
                            <label for="quanbu">
                                <a>全部</a>
                            </label>
                        </li>
                    </ul>
                </li>
                <li>
                    <div style="height: 0px">
                        演员：
                    </div>
                    <ul class="lei_2">
                        <li id="actor">
                            <input type="radio" id="quanbu2" name="quyu" checked>
                            <label for="quanbu2">
                                <a>全部</a>
                            </label>
                        </li>
                    </ul>
                </li>
                <li>
                    <div style="height: 0px">
                        年代：
                    </div>
                    <ul class="lei_2">
                        <li id="time">
                            <input type="radio" id="quanbu3" name="niandai" checked>
                            <label for="quanbu3">
                                <a>全部</a>
                            </label>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>


        <div class="s">
            <input style="display: inline-block;height: 40px;width: 200px;padding: 0 40px 0 20px;border: 1px solid #ccc;font-size: 14px;border-radius: 30px;background-color: #faf8fa;color: #333;outline: none;" class="text" type="search" maxlength="32" placeholder="找影视剧、影人" autocomplete="off">
            <input class="" id="find" style="display: inline-block;position: absolute;height: 40px;width: 40px;border-radius: 30px;outline: none;border: none;background: url(${pageContext.request.contextPath}/front/style/IMG/ding_fangda.png) no-repeat #ef4238 center;" type="submit" value="">
        </div>

        <div class="yingpian">
            <dl id="movie">
            </dl>
        </div>
        <!-- 页 -->
        <div id="demo7"></div>

    </article>
</div>

</body>

<script type="text/javascript" src="${pageContext.request.contextPath}/front/style/JS/jquery.min.js" ></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/front/style/JS/common.js" ></script>

<script>
    $(function () {

        $.ajax({
            async:true,
            url:"${pageContext.request.contextPath}/front/findtype",
            type:"get",
            dataType:"json",
            success:function (result) {
                console.log(result);
                $.each(result,function(index,data) {
                    console.log(data.filmTypeName);
                })
                var context="";
                context=context+"<input type=\"radio\" id=\"quanbu\" name=\"leixing\" checked>\n" +
                    "                            <label for=\"quanbu\">\n" +
                    "                                <a>全部</a>\n" +
                    "                            </label>";

                $.each( result,function(index,type) {
                  context=context+"<input type=\"radio\" id=\"t"+index+"\" name=\"leixing\">\n" +
                      "<label for=\"t"+index+"\">\n" +
                      " <a>"+type.filmTypeName+"</a>\n" +
                      " </label>";
                });

                $("#type").html(context);
            },
            error:function () {
                alert("异步处理失败");
            }
        });


        $.ajax({
            async:true,
            url:"${pageContext.request.contextPath}/front/findReleaseTime",
            type:"get",
            dataType:"json",
            success:function (result) {
                console.log(result);
                var context="";
                context=context+"<input type=\"radio\" id=\"quanbu3\" name=\"niandai\" checked>\n" +
                    "                            <label for=\"quanbu3\">\n" +
                    "                                <a>全部</a>\n" +
                    "                            </label>";

                $.each( result,function(index,data) {
                    context=context+"<input type=\"radio\" id=\"d"+index+"\" name=\"niandai\">\n" +
                        "                            <label for=\"d"+index+"\">\n" +
                        "                                <a>"+data+"</a>\n" +
                        "                            </label>";
                });

                $("#time").html(context);
            },
            error:function () {
                alert("异步处理失败");
            }
        });


        $.ajax({
            async:true,
            url:"${pageContext.request.contextPath}/front/findactor",
            type:"get",
            dataType:"json",
            success:function (result) {
                console.log(result);
                var context="";
                context=context+" <input type=\"radio\" id=\"quanbu2\" name=\"quyu\" checked>\n" +
                    "                            <label for=\"quanbu2\">\n" +
                    "                                <a>全部</a>\n" +
                    "                            </label>";

                $.each( result,function(index,data) {
                    context=context+"    <input type=\"radio\" id=\"a"+index+"\" name=\"quyu\">\n" +
                        "                            <label for=\"a"+index+"\">\n" +
                        "                                <a>"+data.actorName+"</a>\n" +
                        "                            </label>";
                });

                $("#actor").html(context);
            },
            error:function () {
                alert("异步处理失败");
            }
        });

    })
</script>
<script type="text/javascript" src="${pageContext.request.contextPath}/front/layui/layui.js"></script>
<script>
    layui.use(['laypage', 'layer'], function() {
        var laypage = layui.laypage;
        $=layui.$;

        laypage.render({
            elem: 'demo7'
            ,count: 10
            ,theme: '#FF5722'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , jump: function (obj) {
                console.log(obj);
            }
        });
        sendajax(null,null,null,null);

        $("#find").click(function () {
            console.log($("#type :checked").next().find("a").text());
            console.log($("#actor :checked").next().find("a").text());
            console.log($("#time :checked").next().find("a").text());
            console.log($(".text").val());
            var filmName=$(".text").val();
            var filmReleaseTime=$("#time :checked").next().find("a").text();
            var actorName=$("#actor :checked").next().find("a").text();
            var filmTypeName=$("#type :checked").next().find("a").text();
           sendajax(filmName,filmReleaseTime,actorName,filmTypeName)
            //console.log($("#type :checked").parent().find("a").text());
        })

       function sendajax(filmName,filmReleaseTime,actorName,filmTypeName) {
           $.ajax({
               async:true,
               url:"${pageContext.request.contextPath}/front/movie",
               type:"get",
               data:{
                   pageNum:1,
                   pageSize:$(".layui-laypage-limits select").val(),
                   filmName:filmName,
                   filmReleaseTime:filmReleaseTime,
                   actorName:actorName,
                   filmTypeName:filmTypeName
               },
               success:function (result) {
                   console.log(result);
                   var context="";
                   $.each(result.list,function (index,data) {
                       if ("暂无分数"==(data.score)){
                           var score1="暂无分数";
                           var score2="";
                       }else {
                           console.log(data.score);
                           var score = data.score.split(".");
                           var score1 = score[0];
                           var score2 = score[1].substring(0, 2);
                           console.log(score1);
                           console.log(score2);
                       }

                       context=context+"<dd>\n" +
                           "    <div>\n" +
                           "        <i class=\"DIMAX3\"></i>\n" +
                           "        <a href=\"${pageContext.request.contextPath}/front/movieDetail.jsp?filmId="+data.filmId+"\">\n" +
                           "            <img src=\"${pageContext.request.contextPath}/download/img?fileName="+data.filmCover+"\" alt=\"\">\n" +
                           "        </a>\n" +
                           "        <a href=\"${pageContext.request.contextPath}/front/movieDetail.jsp?filmId="+data.filmId+"\">详情</a>\n" +
                           "    </div>\n" +
                           "    <div>\n" +
                           "        <a href=\"${pageContext.request.contextPath}/front/movieDetail.jsp?filmId="+data.filmId+"\" title=\""+data.filmName+"\">"+data.filmName+"</a>\n" +
                           "    </div>\n" +
                           "    <div>\n" +
                           "        <i>"+score1+".</i>\n" +
                           "        <i>"+score2+"</i>\n" +
                           "    </div>\n" +
                           "</dd>";
                   })

                   $("#movie").html(context);

                   laypage.render({
                       elem: 'demo7'
                       ,count:result.total //总记录数
                       ,curr: result.pageNum  //当前页
                       ,limit: 12//当前页显示的记录数
                       ,theme: '#FF5722'
                       , layout: ['count', 'prev', 'page', 'next', 'refresh', 'skip']
                       , jump: function (obj,first) {
                           console.log(obj);
                           // console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                           // console.log(obj.limit); //得到每页显示的条数
                           if(!first){
                               //do something
                               $.ajax({
                                   async:true,
                                   url:"${pageContext.request.contextPath}/front/movie",
                                   type:"get",
                                   data:{
                                       pageNum:obj.curr,
                                       pageSize:obj.limit,
                                       filmName:null,
                                       filmReleaseTime:null,
                                       actorName:null,
                                       filmTypeName:null
                                   },
                                   success:function (result) {
                                       console.log(result);
                                       var context="";
                                       $.each(result.list,function (index,data) {
                                           if ("暂无分数"==(data.score)){
                                               var score1="暂无分数";
                                               var score2="";
                                           }else {
                                               console.log(data.score);
                                               var score = data.score.split(".");
                                               var score1 = score[0];
                                               var score2 = score[1].substring(0, 2);
                                               console.log(score1);
                                               console.log(score2);
                                           }

                                           context=context+"<dd>\n" +
                                               "    <div>\n" +
                                               "        <i class=\"DIMAX3\"></i>\n" +
                                               "        <a href=\"${pageContext.request.contextPath}/front/movieDetail.jsp?filmId="+data.filmId+"\">\n" +
                                               "            <img src=\"${pageContext.request.contextPath}/download/img?fileName="+data.filmCover+"\" alt=\"\">\n" +
                                               "        </a>\n" +
                                               "        <a href=\"${pageContext.request.contextPath}/front/movieDetail.jsp?filmId="+data.filmId+"\">详情</a>\n" +
                                               "    </div>\n" +
                                               "    <div>\n" +
                                               "        <a href=\"${pageContext.request.contextPath}/front/movieDetail.jsp?filmId="+data.filmId+"\" title=\""+data.filmName+"\">"+data.filmName+"</a>\n" +
                                               "    </div>\n" +
                                               "    <div>\n" +
                                               "        <i>"+score1+".</i>\n" +
                                               "        <i>"+score2+"</i>\n" +
                                               "    </div>\n" +
                                               "</dd>";
                                       })

                                       $("#movie").html(context);
                                   }

                               })

                           }
                       }

                   });

               },
               error:function () {
                   alert("异步处理失败");
               }
           })
       }



    })
</script>

<script type="text/javascript">
    // 判断是否登录
    var account = "${sessionScope.account}";
    if(account != ""){
        $(".denglu img").prop("src","${pageContext.request.contextPath}/download/img?fileName=${sessionScope.account.accountPicture}");
        $("#showStatus").text("退出登录");
        $("#showStatus").prop("src","#");
    }
    $(document).on("click","#showStatus",function(){
        if($(this).text()=="退出登录"){
            $.ajax({
                url:"${pageContext.request.contextPath}/front/logout",
                success:function(){
                    console.log("退出成功");
                },
                error:function(){
                    console.log("退出失败");
                }
            });
        }
    })

</script>


</html>